package com.pms.controller;

import java.io.IOException;
import java.util.List;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pms.domain.Saler;
import com.pms.service.SalerService;


/** 
* @ClassName: SalerController 
* @Description:  营业员控制器
* @author ZZW
* @date 2016年12月2日 下午5:56:56 
*  
*/
@Controller
@RequestMapping("/saler")
public class SalerController {

	@Autowired
	private SalerService salerService;

	/**
	 * 获得所有对象
	 * @author ZZW
	 * @return
	 * @throws IOException
	 */
	@RequestMapping(value = "/query.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getSalers() throws IOException {
		List<Saler> salerList = salerService.getAll() ;
		
		return new String(JSONObject.valueToString(salerList).toString().getBytes(),"utf-8");
	}
	
	/**
	 * 取得单个对象
	 * @author ZZW
	 * @param cardId
	 * @throws IOException
	 */
	@RequestMapping(value = "/getById.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public String getSalerById(@RequestParam(value="cardId")String cardId) throws IOException {
		Saler saler = salerService.selectByCardId(cardId) ;
		return new String(JSONObject.valueToString(saler).toString().getBytes(),"utf-8");
	}
	
	/**
	 * 添加
	 * @author ZZW
	 * @param saler
	 * @throws IOException
	 */
	@RequestMapping(value = "/insert.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void insertSalerById(@RequestParam(value="saler") Saler saler) throws IOException {
		salerService.insertSaler(saler);
	}
	
	/**
	 * 更新
	 * @author ZZW
	 * @param saler
	 * @throws IOException
	 */
	@RequestMapping(value = "/update.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void updateSaler(@RequestParam(value="saler") Saler saler) throws IOException {
		salerService.updateByCardId(saler);
	}
	
	/**
	 * 删除
	 * @author ZZW
	 * @param cardId
	 * @throws IOException
	 */
	@RequestMapping(value = "/delete.pfv",method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void deleteSaler(@RequestParam(value="cardId") String cardId) throws IOException {
		salerService.deleteSalerByCardId(cardId);
	}
	
}
